//
//  ParkingHomeController.m
//  HuLaQuan
//
//  Created by hok on 3/15/16.
//  Copyright © 2016 yuwubao. All rights reserved.
//

#import "ParkingHomeController.h"

//Cells
#import "ParkingHomeCell.h"

@interface ParkingHomeController ()

@property (weak, nonatomic) IBOutlet UICollectionView *functionItemsView;
@property (strong, nonatomic) NSArray *items;

@end

@implementation ParkingHomeController

static NSString * const ParkingHomeCellIdentifier = @"ParkingHomeCell";

- (NSArray *)items
{
    if(!_items) _items=[NSMutableArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"ParkingHomeItems" ofType:@"plist"]];
    return _items;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}
- (void)setupUI
{
    self.title = @"停车缴费";
    
    [self setupNavBackButton];
    
    [self.functionItemsView registerNib:[ParkingHomeCell nib] forCellWithReuseIdentifier:ParkingHomeCellIdentifier];
    self.functionItemsView.backgroundColor = [UIColor whiteColor];
}

#pragma mark - UICollectionViewDataSource
//定义展示的UICollectionViewCell的个数
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    
    return self.items.count;
    
    
}
//定义展示的Section的个数
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}
//每个UICollectionView展示的内容
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    if ([collectionView isEqual:self.functionItemsView]) {
        ParkingHomeCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ParkingHomeCellIdentifier forIndexPath:indexPath];
        // [cell sizeToFit];
        
        
        
        if (IS_IPHONE_6P) {
            
            cell.imageWidth.constant = cell.imageWidth.constant * 1.3;
            cell.imageHeight.constant = cell.imageHeight.constant * 1.3;
            cell.imageTop.constant = cell.imageTop.constant - 3;
            cell.itemTitle.font =  [UIFont fontWithName:FONT_NAME size:15];
        }
        
        cell.indexPath = indexPath;
        cell.itemTitle.text = self.items[indexPath.row][@"title"];
        cell.itemImageName = self.items[indexPath.row][@"image"];
        
        
        
     
        
        return cell;
    }
    
    return nil;
    
}
//定义每个UICollectionView 的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(self.functionItemsView.bounds.size.width /3, self.functionItemsView.bounds.size.height /2);
    
    
}
//定义每个UICollectionView 的间距
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(0, 0, 0, 0);
}


//返回这个UICollectionView是否可以被选择
-(BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}
#pragma mark - UICollectionViewDelegate
//UICollectionView被选中时调用的方法
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    // NSLog(@"select %d",indexPath.row);
    
    //  UIStoryboard *convPayStoryBoard = [UIStoryboard storyboardWithName:@"ConvenientPay" bundle:nil];
    
    switch (indexPath.row) {
        case 0:
            [self performSegueWithIdentifier:@"ShowCarList" sender:self];
            break;
        case 1:
            [self performSegueWithIdentifier:@"ShowParkingRecord" sender:self];
            break;
        
        default:
            break;
    }
    
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
